package cc.rengu.igas.bsps.core.service.trans;

import cc.rengu.igas.bsps.common.enums.DubboServiceEnum;
import cc.rengu.igas.bsps.common.enums.RespCodeEnum;
import cc.rengu.igas.bsps.common.util.ChangeDubboUtil;
import cc.rengu.igas.bsps.core.service.base.ManageService;
import cc.rengu.igas.momp.facade.request.QueryCashierCashbackMcListInfoRequest;
import cc.rengu.igas.momp.facade.response.QueryCashierCashbackMcListInfoResponse;
import cc.rengu.igas.momp.facade.result.Result;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.service.realize.DubboService;
import cc.rengu.oltp.service.realize.impl.DubboServiceImpl;
import cc.rengu.oltp.utility.util.ConvertUtil;

/**
 * @author Xuegui Cao
 * @date 2020/7/1
 * @description 收银员返现营销活动列表查询
 */
public class QueryCashierCashbackMcListService extends ManageService {

    @Override
    protected Object bizBeforeCust() throws Exception {
        QueryCashierCashbackMcListInfoRequest request = new QueryCashierCashbackMcListInfoRequest();
        // 读取存在xml树里的实体类
        ConvertUtil.convertOutput(request);
        return request;
    }

    @Override
    protected BizResponse bizProcessCust(Object request) throws Exception {
        QueryCashierCashbackMcListInfoRequest dubboRequest = (QueryCashierCashbackMcListInfoRequest) request;
        dubboRequest.setQueryOrgId(ChangeDubboUtil.getSignInstId());

        //修改请求Header
        ChangeDubboUtil.changeHeader(dubboRequest.getHeader(), DubboServiceEnum.M00MO021.getTxnNum());

        //调用Dubbo，获取结果集和相应对象。
        DubboService dubboService = new DubboServiceImpl();
        Result<QueryCashierCashbackMcListInfoResponse> result = (Result<QueryCashierCashbackMcListInfoResponse>) dubboService.callDubboService(DubboServiceEnum.M00MO021.getServerName(), DubboServiceEnum.M00MO021.getMethodName(), dubboRequest);
        if (result != null && result.isSuccess()) {
            //调用成功
            BizResponse<QueryCashierCashbackMcListInfoResponse> bizResponse = new BizResponse<>();
            ChangeDubboUtil.setBizResponse(bizResponse, AppParamConstant.SYS_ID, result);
            return bizResponse;
        } else {
            rglog.error("【商户服务】调用【{}】服务异常！", DubboServiceEnum.M00MO021.getDescription());
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }
    }

    @Override
    protected void bizAfterCust(Object response) throws Exception {
        BizResponse bizResponse = (BizResponse) response;
        QueryCashierCashbackMcListInfoResponse modelRespose = (QueryCashierCashbackMcListInfoResponse) bizResponse.getResult();
        ConvertUtil.convertInput(modelRespose);
    }
}
